<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  
  <title>ElasticSearch入门 | conor_hua</title>
  <meta name="description" content="辉夜大小姐想让我写博客。" />
  <meta name="keywords" content="Java,Sakura,spring" />
  
    <link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/favicon00.ico">
  
  <meta http-equiv="x-dns-prefetch-control" content="on">
  <!--自定义看板娘-->
  <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
  <script src="/live2d-widget/autoload.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/googlefont.css" media="all">
<!--  <link rel="dns-prefetch" href="//cdn.jsdelivr.net">-->
  <link rel="stylesheet" id="saukra_css-css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/style.css" type="text/css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/lib.min.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/font.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/insight.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/jquery.fancybox.min.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/zoom.css" media="all">
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/sharejs.css">
  <link rel="stylesheet" href="/css/tags.css" media="all">
  <!--   <link rel="stylesheet" id="saukra_css-css" href="https://2heng.xin/wp-content/cache/autoptimize/css/autoptimize_ad42a61f4c7d4bdd9f91afcff6b5dda5.css
" type="text/css" media="all"> -->
  <script>
  /*Initial Variables*/
  var mashiro_option = new Object();
  var mashiro_global = new Object();
  mashiro_option.NProgressON = true;
  /* 
   * 邮箱信息之类的东西可以填在这里，这些js变量基本都作用于sakura-app.js
   * 这样的设置仅是为了方便在基于PHP开发的主题中设置js变量，既然移植到了Node上，我想或许可以精简这一逻辑吧
   */
  mashiro_option.email_domain = "";
  mashiro_option.email_name = "";
  mashiro_option.cookie_version_control = "";
  mashiro_option.qzone_autocomplete = false;
  mashiro_option.site_name = "Conor_hua";
  mashiro_option.author_name = "";
  mashiro_option.site_url = "https://conor_hua.gitee.io";
  mashiro_option.v_appId = "GyC3NzMvd0hT9Yyd2hYIC0MN-gzGzoHsz";
  mashiro_option.v_appKey = "mgOpfzbkHYqU92CV4IDlAUHQ";
  mashiro_option.mathjax = "0";
  mashiro_option.qq_api_url = "https://api.mashiro.top/qqinfo/"; 
  mashiro_option.qq_avatar_api_url = "https://api.mashiro.top/qqinfo/";

  // mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/moezx/cdn@3.4.5/css/lib.min.css";
  // mashiro_option.float_player_on = true;

  /*End of Initial Variables*/
  </script>
  <script type="text/javascript">
  var bg = "https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/6f005cbc1865ff1b706aba57347988ab.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/ox83gp.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/a5fa4f9db760f58fc48f03d66b4967f7.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/zm3vey.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/b3e8dae89b950b940dc0edd1e8cc0566.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/j58y6y.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/4217z9.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/j5zg2p.jpg".split(",");
  var bgindex = Math.floor(Math.random()*bg.length);
  if (!!window.ActiveXObject || "ActiveXObject" in window) { //is IE?
    alert('朋友，IE浏览器未适配哦~');
  }
  </script>
  <style type="text/css">
  .hljs-ln{border-collapse:collapse}.hljs-ln td{padding:0}.hljs-ln-n:before{content:attr(data-line-number)}
  </style>
  <style type="text/css">.site-top .lower nav{display:block !important;}.author-profile i,.post-like a,.post-share .show-share,.sub-text,.we-info a,span.sitename,.post-more i:hover,#pagination a:hover,.post-content a:hover,.float-content i:hover{color:#FE9600}.feature i,.download,.navigator i:hover,.links ul li:before,.ar-time i,span.ar-circle,.object,.comment .comment-reply-link,.siren-checkbox-radio:checked + .siren-checkbox-radioInput:after{background:#FE9600}::-webkit-scrollbar-thumb{background:#FE9600}.download,.navigator i:hover,.link-title,.links ul li:hover,#pagination a:hover,.comment-respond input[type='submit']:hover{border-color:#FE9600}.entry-content a:hover,.site-info a:hover,.comment h4 a,#comments-navi a.prev,#comments-navi a.next,.comment h4 a:hover,.site-top ul li a:hover,.entry-title a:hover,#archives-temp h3,span.page-numbers.current,.sorry li a:hover,.site-title a:hover,i.iconfont.js-toggle-search.iconsearch:hover,.comment-respond input[type='submit']:hover{color:#FE9600}.comments .comments-main{display:block !important;}.comments .comments-hidden{display:none !important;}background-position:center center;background-attachment:inherit;}
  </style>
<script src="https://cdn.jsdelivr.net/gh/conorhua/asset/js/hititle.js"></script>
<meta name="generator" content="Hexo 4.2.1"></head>

<body class="page-template page-template-user page-template-page-analytics page-template-userpage-analytics-php page page-id-1297 chinese-font serif isWebKit">
  <div class="scrollbar" id="bar">
  </div>
  <a href="#" class="cd-top faa-float animated"></a>
  <section id="main-container">
    <div class="headertop filter-dot">
  <div id="banner_wave_1"></div>
  <div id="banner_wave_2"></div>
  <figure id="centerbg" class="centerbg">
    <div class="focusinfo no-select">
      <div class="header-tou">
        <a href="https://conor_hua.gitee.io" target="_blank" rel="noopener">
          <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
        </a>
      </div>
      <div class="header-info">
        <p id="jinrishici-sentence">正在加载今日诗词....</p>
        <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
        <div class="top-social_v2">
          <li id="bg-pre">
            <img class="flipx" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
          
          
          
          <li>
            <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=1_bi5eLm4_Tj4uGXpqb5tLi6" target="_blank" class="social-github" title="email">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/email.png">
            </a>
          </li>
          
          
          
          <li class="wechat">
            <a href="/#">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/wechat.png">
            </a>
            <div class="wechatInner">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/1.jpg">
            </div>
          </li>
          
          
          
          <li id="bg-next">
            <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
        </div>
      </div>
    </div>
  </figure>
  
  <div id="video-container" style="display: none;">
    <video style="object-fit: fill" id="bgvideo" class="video" video-name="" src="" width="auto" preload="auto">
    </video>
    <div id="video-btn" class="loadvideo videolive">
    </div>
    <div id="video-add">
    </div>
    <div class="video-stu">
    </div>
  </div>
  
  <div class="headertop-down faa-float animated" onclick="headertop_down()">
    <span>
      <i class="fa fa-chevron-down" aria-hidden="true">
      </i>
    </span>
  </div>
</div>
    <div id="page" class="site wrapper">
      <header class="site-header no-select gizle sabit" role="banner">
 
  <div class="site-top">
    <div class="site-branding">
      <span class="site-title">
        <span class="logolink moe-mashiro">
          <a href="/">
            <span class="sakurasono">Conor_hua</span>
            <span class="shironeko"></span>
          </a>
        </span>
      </span>
    </div>
    <div class="searchbox search-form-submit">
      <i class="iconfont js-toggle-search iconsearch icon-search">
      </i>
    </div>
    <div id="show-nav" class="showNav mobile-fit">
      <div class="line line1">
      </div>
      <div class="line line2">
      </div>
      <div class="line line3">
      </div>
    </div>
    <div class="lower-cantiner">
      <div class="lower">
        <nav class="mobile-fit-control hide">
          <ul id="menu-new" class="menu">
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
                    首页
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/archives">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
                    归档
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/categories/%E6%8A%80%E6%9C%AF/">
                          <i class="fa fa-code" aria-hidden="true"></i>
                          技术
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E5%B9%B2%E8%B4%A7/">
                          <i class="fa fa-plug" aria-hidden="true"></i>
                          干货
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
                    清单
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/bangumis/">
                          <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                          番剧
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E6%94%B6%E8%97%8F/">
                          <i class="fa fa-star" aria-hidden="true"></i>
                          收藏
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/tags/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-tags" aria-hidden="true"></i>
                    标签
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
                    关于
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/about/">
                          <i class="fa fa-meetup" aria-hidden="true"></i>
                          我？
                        </a>
                      </li>
                    
                      <li>
                        <a href="/theme-sakura/">
                          <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                          主题
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/links/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
                    友人帐
                  </span>
                </a>
                
              </li>
            
          </ul>
        </nav>
      </div>
    </div>
  </div>
</header>

      <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/sharejs.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/tocbot.css">
<div class="pattern-center-blank"></div>

  <div class="pattern-center single-center">
    <!-- 有配图默认渲染第一张 -->
    <div class="pattern-attachment-img">
        <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-p86xrj.jpg" class="lazyload" onerror="imgError(this,3)" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;">
      </div>
    <header class="pattern-header single-header">
      <h1 class="entry-title">
      ElasticSearch入门</h1>
      <p class="entry-census">
        <span>
          <a href="">
            <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
          </a>
        </span>
        <span>
          <a href="">Conor_hua</a>
        </span>
        <span class="bull">
        ·</span>
        2021-11-5
        
      
        ·<span id="readcount"></span>次阅读
      
      </p>
    </header>
  </div>

<div id="content" class="site-content">
  <div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
      <article id="post-1" class="post-1 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized">
        <div class="toc"></div>
        <!--<div class="toc-entry-content"> <!-- 套嵌目录使用（主要为了支援评论）-->
        
        <div class="entry-content">
          <p>本博客是ElasticSearch学习的笔记。主要是记录方便日后回档。</p>
<p>本文参考文章如下：</p>
<p><a href="https://www.elastic.co/cn/" target="_blank" rel="noopener">ElasticSearch</a></p>
<p><a href="https://baike.baidu.com/item/elasticsearch/3411206?fr=aladdin" target="_blank" rel="noopener">ElasticSearch-百科</a></p>
<p><a href="https://www.cnblogs.com/sunsky303/p/9438737.html" target="_blank" rel="noopener">ElasticSearch入门</a></p>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>​        ElasticSearch是一个基于<a href="https://baike.baidu.com/item/Lucene/6753302" target="_blank" rel="noopener">Lucene</a>的搜索服务器。它开源，免费，提供了一个分布式多用户能力的<a href="https://baike.baidu.com/item/全文搜索引擎/7847410" target="_blank" rel="noopener">全文搜索引擎</a>，基于RESTful web接口，是一个流行的企业级搜索引擎。</p>
<h2 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h2><ul>
<li>cluster(集群)：由一个或多个节点组成的系统，对外呈现为一个提供完整服务的服务器；</li>
<li>node(节点)：集群中的一个服务器即为一个节点，作为集群的一部分；</li>
<li>index(索引)：拥有相同特征的document(文档)的集合，类似于关系型数据库中database的概念；</li>
<li>type(类型)：一个index中可以定义一种或多种type，一个type是index的一个逻辑分区，类似于table的概念</li>
<li>document(文档)：一个document是一个可被索引的基础信息单元，一json格式表示，类似于record的概念。</li>
</ul>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><p>ElasticSearch可以基于restful风格进行操作。</p>
<p>建议使用kibana工具进行操作</p>
<h3 id="脚本操作"><a href="#脚本操作" class="headerlink" title="脚本操作"></a>脚本操作</h3><h4 id="索引简单操作"><a href="#索引简单操作" class="headerlink" title="索引简单操作"></a>索引简单操作</h4><pre><code class="javascript">#创建索引
put person

#查询索引
GET person

#删除索引
DELETE person

#添加映射
PUT person/_mapping
{
  &quot;properties&quot;:{
    &quot;name&quot;:{
      &quot;type&quot;: &quot;keyword&quot;
    },
    &quot;age&quot;:{
      &quot;type&quot;: &quot;integer&quot;
    }
  }
}

#创建索引的同时添加映射
PUT person
{
  &quot;mappings&quot;: {
    &quot;properties&quot;:{
      &quot;name&quot;:{
        &quot;type&quot;: &quot;keyword&quot;
      },
      &quot;age&quot;:{
        &quot;type&quot;: &quot;integer&quot;
      }
    }
  }
}</code></pre>
<h4 id="document操作"><a href="#document操作" class="headerlink" title="document操作"></a>document操作</h4><pre><code class="javascript">#查询document
GET person/_doc/1

#查询所有document
GET person/_search


#添加document 不存在则添加，存在则修改
POST person/_doc/1
{
  &quot;name&quot;: &quot;一哥&quot;,
  &quot;age&quot;: &quot;18&quot;
}

#添加document - 不指定ID 自动生成ID
POST person/_doc/
{
  &quot;name&quot;: &quot;老二&quot;,
  &quot;age&quot;: &quot;18&quot;
}

#删除document
DELETE person/_doc/1</code></pre>
<h4 id="批量操作"><a href="#批量操作" class="headerlink" title="批量操作"></a>批量操作</h4><pre><code class="javascript">#批量操作 bulk
POST _bulk
{&quot;create&quot;:{&quot;_index&quot;: &quot;person&quot;,&quot;_id&quot;:&quot;2&quot;}}
{&quot;name&quot;:&quot;2333&quot;,&quot;age&quot;:&quot;11&quot;}
{&quot;create&quot;:{&quot;_index&quot;: &quot;person&quot;,&quot;_id&quot;:&quot;3&quot;}}
{&quot;name&quot;:&quot;2333&quot;,&quot;age&quot;:&quot;22&quot;}
{&quot;delete&quot;:{&quot;_index&quot;: &quot;person&quot;,&quot;_id&quot;:&quot;3&quot;}}
{&quot;update&quot;:{&quot;_index&quot;: &quot;person&quot;,&quot;_id&quot;:&quot;2&quot;}}
{&quot;doc&quot;:{ &quot;name&quot;:&quot;2333&quot;,&quot;age&quot;:&quot;33&quot;}}</code></pre>
<h4 id="match-all"><a href="#match-all" class="headerlink" title="match_all"></a>match_all</h4><pre><code class="javascript">#查询全部
GET kibana_sample_data_logs/_search
{
  &quot;query&quot;: {
    &quot;match_all&quot;: {}
  }
}

#查询全部 返回条数
GET kibana_sample_data_logs/_search
{
  &quot;query&quot;: {
    &quot;match_all&quot;: {}
  },
  &quot;from&quot;: 0,
  &quot;size&quot;: 20
}</code></pre>
<h4 id="term"><a href="#term" class="headerlink" title="term"></a>term</h4><p>精准查询，完全匹配，不会对字段进行分词，适合keyword、numeric、date等明确值的。</p>
<pre><code class="javascript">GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;term&quot;: {
      &quot;day_of_week_i&quot;: {
        &quot;value&quot;: &quot;6&quot;
      }
    }
  }
}</code></pre>
<h4 id="match"><a href="#match" class="headerlink" title="match"></a>match</h4><p>match匹配是全文搜索，会对field进行分词，默认取or 并集，</p>
<pre><code class="javascript">GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;match&quot;: {
      &quot;category&quot;: &quot;Men&#39;S Clothing&quot;
    }
  }
}

GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;match&quot;: {
      &quot;category&quot;: {
        &quot;query&quot;: &quot;Men&#39;S Clothing&quot;,
        &quot;operator&quot;: &quot;and&quot; #交集
      }
    }
  }
}
</code></pre>
<h4 id="模糊匹配"><a href="#模糊匹配" class="headerlink" title="模糊匹配"></a>模糊匹配</h4><ul>
<li><p>wirdcard 模糊查询 分词匹配 *任意个 ?一个</p>
</li>
<li><p>regexp 模糊查询 正则匹配 </p>
</li>
<li><p>prefix 模糊查询 前缀匹配</p>
</li>
</ul>
<pre><code class="java">
#wirdcard 模糊查询 分词匹配 *任意个 ?一个
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;wildcard&quot;: {
      &quot;category&quot;: {
        &quot;value&quot;: &quot;men&#39;s*&quot;
      }
    }
  }
}

#regexp 模糊查询 正则匹配 
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;regexp&quot;: {
      &quot;category&quot;: &quot;men+(.)*&quot;
    }
  }
}

#prefix 模糊查询 前缀匹配
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;prefix&quot;: {
      &quot;category&quot;: {
        &quot;value&quot;: &quot;m&quot;
      }
    }
  }
}</code></pre>
<h4 id="范围查询"><a href="#范围查询" class="headerlink" title="范围查询"></a>范围查询</h4><p>range用于范围匹配</p>
<pre><code class="javascript">#范围查询  range
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;range&quot;: {
      &quot;taxless_total_price&quot;: {
        &quot;gte&quot;: 100,
        &quot;lte&quot;: 200
      }
    }
  }
}

#结合sort排序
#范围查询  range
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;range&quot;: {
      &quot;taxless_total_price&quot;: {
        &quot;gte&quot;: 100,
        &quot;lte&quot;: 200
      }
    }
  },
  &quot;sort&quot;: [
    {
      &quot;taxless_total_price&quot;: {
        &quot;order&quot;: &quot;desc&quot;
      }
    }
  ]
}

</code></pre>
<h4 id="QueryString"><a href="#QueryString" class="headerlink" title="QueryString"></a>QueryString</h4><p>会分词，等值匹配，默认取并集，跟match差不多，但可指定多字段</p>
<pre><code class="javascript">#默认并集，query内可以指定分词，fields可以指定多字段
#&quot;Sultan and Pratt&quot; 即 &quot;Sultan&quot; and &quot;Pratt&quot;
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;query_string&quot;: {
      &quot;fields&quot;: [&quot;customer_first_name&quot;, &quot;customer_full_name&quot;],
      &quot;query&quot;: &quot;Sultan Pratt&quot;,
      &quot;default_operator&quot;: &quot;or&quot;
    }
  }
}

</code></pre>
<p>simple_query_string和QueryString类似，但是不支持+ -操作，如：</p>
<pre><code class="javascript">#包含Sultan 不包含Pratt
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;query_string&quot;: {
      &quot;fields&quot;: [&quot;customer_first_name&quot;, &quot;customer_full_name&quot;],
      &quot;query&quot;: &quot;+Sultan  -Pratt&quot;,
      &quot;default_operator&quot;: &quot;or&quot;
    }
  }
}</code></pre>
<h4 id="bool查询"><a href="#bool查询" class="headerlink" title="bool查询"></a>bool查询</h4><p>包括四个子句must，filter,should,must_not</p>
<p>其中filter较快，filter不进行得分计算且对结果进行缓存</p>
<p><strong>must</strong></p>
<p>返回的文档必须满足must子句的条件，并且参与计算分值</p>
<p><strong>filter</strong></p>
<p>返回的文档必须满足filter子句的条件。但是不会像Must一样，参与计算分值</p>
<p><strong>should</strong></p>
<p>返回的文档可能满足should子句的条件。在一个Bool查询中，如果没有must或者filter，有一个或者多个should子句，那么只要满足一个就可以返回。<code>minimum_should_match</code>参数定义了至少满足几个子句。</p>
<p><strong>must_not</strong></p>
<p>返回的文档必须不满足must_not定义的条件。</p>
<pre><code class="java">#bool查询
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;must&quot;: [
        {
          &quot;term&quot;: {
            &quot;day_of_week&quot;: {
              &quot;value&quot;: &quot;Monday&quot;
            }
          }
        },
        {
          &quot;match&quot;: {
            &quot;category&quot;: &quot;men&#39;s &quot;
          }
        }
      ]
    }
  }
}

#bool查询
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;bool&quot;: {
      &quot;must&quot;: [
        {
          &quot;term&quot;: {
            &quot;day_of_week&quot;: {
              &quot;value&quot;: &quot;Monday&quot;
            }
          }
        }
      ],
      &quot;filter&quot;: [
         {
          &quot;match&quot;: {
            &quot;category&quot;: &quot;men&#39;s&quot;
          }
        }
      ]
    }
  }
}</code></pre>
<h4 id="聚合查询"><a href="#聚合查询" class="headerlink" title="聚合查询"></a>聚合查询</h4><ul>
<li>指标聚合：相当于MySQL中的聚合函数，max，min，count，avg等</li>
<li>桶聚合：相当于MySQL的group by操作</li>
</ul>
<p><strong>指标聚合</strong>:</p>
<pre><code class="java">#聚合查询
#指标聚合
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;match&quot;: {
      &quot;category&quot;: &quot;men&#39;s&quot;
    }
  },
  &quot;aggs&quot;: {
    &quot;max_price&quot;: {
      &quot;max&quot;: {
        &quot;field&quot;: &quot;taxless_total_price&quot;
      }
    }
  }
}</code></pre>
<p>聚合部分结果：</p>
<pre><code class="java">  &quot;aggregations&quot; : {
    &quot;max_price&quot; : {
      &quot;value&quot; : 2250.0
    }
  }</code></pre>
<p><strong>桶聚合</strong>:</p>
<pre><code class="java">#聚合查询
#桶聚合
GET kibana_sample_data_ecommerce/_search
{
  &quot;query&quot;: {
    &quot;match&quot;: {
      &quot;category&quot;: &quot;men&#39;s&quot;
    }
  },
  &quot;aggs&quot;: {
    &quot;name&quot;: {
      &quot;terms&quot;: {
        &quot;field&quot;: &quot;day_of_week_i&quot;,
        &quot;size&quot;: 100
      }
    }
  }
}</code></pre>
<p>聚合部分结果：</p>
<pre><code class="java">&quot;aggregations&quot; : {
    &quot;name&quot; : {
      &quot;doc_count_error_upper_bound&quot; : 0,
      &quot;sum_other_doc_count&quot; : 0,
      &quot;buckets&quot; : [
        {
          &quot;key&quot; : 5,
          &quot;doc_count&quot; : 382
        },
        {
          &quot;key&quot; : 4,
          &quot;doc_count&quot; : 380
        },
        {
          &quot;key&quot; : 3,
          &quot;doc_count&quot; : 368
        },
        {
          &quot;key&quot; : 6,
          &quot;doc_count&quot; : 309
        },
        {
          &quot;key&quot; : 2,
          &quot;doc_count&quot; : 308
        },
        {
          &quot;key&quot; : 1,
          &quot;doc_count&quot; : 296
        },
        {
          &quot;key&quot; : 0,
          &quot;doc_count&quot; : 267
        }
      ]
    }</code></pre>
<h4 id="返回结果解释"><a href="#返回结果解释" class="headerlink" title="返回结果解释"></a>返回结果解释</h4><pre><code class="javascript">{
  &quot;took&quot; : 1,   #搜索用时，单位是毫秒。重复查询用时会变少，结果会被缓存？
  &quot;timed_out&quot; : false, #是否超时
  &quot;_shards&quot; : {  #暂时不知道，指示搜索了多少分片
    &quot;total&quot; : 1,
    &quot;successful&quot; : 1,
    &quot;skipped&quot; : 0,
    &quot;failed&quot; : 0
  },
  &quot;hits&quot; : {  #搜索的结果集
    &quot;total&quot; : {  
      &quot;value&quot; : 10000,  #命中个数 ，并不一定准确
      &quot;relation&quot; : &quot;gte&quot;  #操作方式 ，
    },
    &quot;max_score&quot; : 1.0, #得分，默认根据得分排序
    &quot;hits&quot; : [ #搜索结果的数组，默认返回10条
            **data**
        ]
    }
}
</code></pre>
<p>确切来说默认情况下，hits.total.value是不确切的命中计数，在这种情况下，当hits.total.relation的值是eq时，hits.total.value的值是准确计数。当hits.total.relation的值是gte时，hits.total.value的值是不准确的。</p>
<h3 id="JavaAPI"><a href="#JavaAPI" class="headerlink" title="JavaAPI"></a>JavaAPI</h3><p>项目使用elasticsearch-rest-high-level-client进行操作ES，故这里先主要学习Java API操作。</p>
<h4 id="引用maven依赖："><a href="#引用maven依赖：" class="headerlink" title="引用maven依赖："></a>引用maven依赖：</h4><pre><code class="xml">&lt;dependency&gt;
            &lt;groupId&gt;org.elasticsearch&lt;/groupId&gt;
            &lt;artifactId&gt;elasticsearch&lt;/artifactId&gt;
            &lt;version&gt;${elasticsearch.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
            &lt;artifactId&gt;elasticsearch-rest-client&lt;/artifactId&gt;
            &lt;version&gt;${elasticsearch.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
            &lt;artifactId&gt;elasticsearch-rest-high-level-client&lt;/artifactId&gt;
            &lt;version&gt;${elasticsearch.version}&lt;/version&gt;
        &lt;/dependency&gt;</code></pre>
<h4 id="配置类："><a href="#配置类：" class="headerlink" title="配置类："></a>配置类：</h4><pre><code class="java">@Configuration
public class ElasticSearchConfig {
    @Bean
    public RestHighLevelClient client(){

        return new RestHighLevelClient(RestClient.builder(
                new HttpHost(
                        host,
                        port,
                        &quot;http&quot;
                )
        ));
    }
}</code></pre>
<h4 id="索引操作"><a href="#索引操作" class="headerlink" title="索引操作"></a>索引操作</h4><h5 id="创建索引："><a href="#创建索引：" class="headerlink" title="创建索引："></a>创建索引：</h5><pre><code class="java">    @Test
    void createIndex() throws IOException {
        //获取操作索引的对象
        IndicesClient indicesClient=client.indices();
        //具体操作
        CreateIndexRequest createIndexRequest=new CreateIndexRequest(&quot;person2&quot;);
        CreateIndexResponse createIndexResponse=indicesClient.create(createIndexRequest, RequestOptions.DEFAULT);

        System.out.println(createIndexResponse.isAcknowledged());

    }</code></pre>
<h5 id="查询索引"><a href="#查询索引" class="headerlink" title="查询索引:"></a>查询索引:</h5><pre><code class="java">    @Test
    void getIndex() throws IOException {
        //获取操作索引的对象
        IndicesClient indicesClient=client.indices();
        //具体操作
        GetIndexRequest getIndexRequest=new GetIndexRequest(&quot;person&quot;);
        GetIndexResponse getIndexResponse = indicesClient.get(getIndexRequest, RequestOptions.DEFAULT);
        for( String key : getIndexResponse.getMappings().keySet() ){
            System.out.println(key + &quot;:&quot; + getIndexResponse.getMappings().get(key).getSourceAsMap());
        }

    }</code></pre>
<h5 id="删除索引"><a href="#删除索引" class="headerlink" title="删除索引"></a>删除索引</h5><pre><code class="java">    @Test
    void deleteIndex() throws IOException {
        //获取操作索引的对象
        IndicesClient indicesClient=client.indices();
        //具体操作
        DeleteIndexRequest deleteIndexRequest=new DeleteIndexRequest(&quot;person2&quot;);
        AcknowledgedResponse delete = indicesClient.delete(deleteIndexRequest, RequestOptions.DEFAULT);

        System.out.println(delete.isAcknowledged());
    }</code></pre>
<h5 id="判断索引是否存在"><a href="#判断索引是否存在" class="headerlink" title="判断索引是否存在"></a>判断索引是否存在</h5><pre><code class="java">    @Test
    void isIndex() throws IOException {
        //获取操作索引的对象
        IndicesClient indicesClient=client.indices();
        //具体操作
        GetIndexRequest getIndexRequest=new GetIndexRequest(&quot;person&quot;);
        boolean exists = indicesClient.exists(getIndexRequest, RequestOptions.DEFAULT);

        System.out.println(exists);
    }</code></pre>
<h4 id="文档操作"><a href="#文档操作" class="headerlink" title="文档操作"></a>文档操作</h4><h5 id="添加文档"><a href="#添加文档" class="headerlink" title="添加文档"></a>添加文档</h5><pre><code class="java">    @Test
    void addDocument() throws IOException {

        Map&lt;String, String&gt; data=new HashMap&lt;&gt;();
        data.put(&quot;name&quot;,&quot;hhhhha&quot;);
        data.put(&quot;age&quot;,&quot;12&quot;);
        IndexRequest indexRequest=new IndexRequest(&quot;person&quot;).source(data);
        IndexResponse indexResponse=client.index(indexRequest,RequestOptions.DEFAULT);

        System.out.println(indexResponse.getId());
    }</code></pre>
<h5 id="查询文档"><a href="#查询文档" class="headerlink" title="查询文档"></a>查询文档</h5><pre><code class="java">    @Test
    void getDocument() throws IOException {

        GetRequest getRequest=new GetRequest(&quot;person&quot;).id(&quot;2&quot;);
        GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);

        System.out.println(getResponse.getSource());
    }</code></pre>
<h5 id="删除文档"><a href="#删除文档" class="headerlink" title="删除文档"></a>删除文档</h5><pre><code class="java">    @Test
    void deleteDocument() throws IOException {

        DeleteRequest deleteRequest=new DeleteRequest(&quot;person&quot;).id(&quot;2&quot;);
        DeleteResponse Response = client.delete(deleteRequest, RequestOptions.DEFAULT);

        System.out.println(Response.getId());
    }</code></pre>
<h4 id="批量操作-1"><a href="#批量操作-1" class="headerlink" title="批量操作"></a>批量操作</h4><pre><code class="java">    @Test
    void bulkDocument() throws IOException {
        //批量操作的对象
        BulkRequest bulkRequest=new BulkRequest();
        //创建
        Map&lt;String,String&gt; map1=new HashMap&lt;&gt;();
        map1.put(&quot;name&quot;,&quot;test&quot;);
        map1.put(&quot;age&quot;,&quot;11&quot;);
        IndexRequest indexRequest1=new IndexRequest(&quot;person&quot;).id(&quot;11&quot;).source(map1);
        bulkRequest.add(indexRequest1);
        //创建
        Map&lt;String,String&gt; map2=new HashMap&lt;&gt;();
        map2.put(&quot;name&quot;,&quot;test2&quot;);

        IndexRequest indexRequest2=new IndexRequest(&quot;person&quot;).id(&quot;22&quot;).source(map2);
        bulkRequest.add(indexRequest2);
        //删除
        DeleteRequest deleteRequest=new DeleteRequest(&quot;person&quot;).id(&quot;22&quot;);
        bulkRequest.add(deleteRequest);

        BulkResponse bulkResponse=client.bulk(bulkRequest,RequestOptions.DEFAULT);
        System.out.println(bulkResponse.status());
    }</code></pre>
<h4 id="match-all-1"><a href="#match-all-1" class="headerlink" title="match_all"></a>match_all</h4><pre><code class="java">    @Test
    void matchAll() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_logs&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        MatchAllQueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //分页， 默认10条
        searchRequestBuilder.from(0);
        searchRequestBuilder.size(100);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }</code></pre>
<h4 id="term-1"><a href="#term-1" class="headerlink" title="term"></a>term</h4><p>精准查询，完全匹配，不会对字段进行分词，适合keyword、numeric、date等明确值的。</p>
<pre><code class="java">    @Test
    void term() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        TermQueryBuilder queryBuilder = QueryBuilders.termQuery(&quot;day_of_week_i&quot;, &quot;6&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }</code></pre>
<h4 id="match-1"><a href="#match-1" class="headerlink" title="match"></a>match</h4><p>match匹配是全文搜索，会对field进行分词，默认取or 并集，</p>
<pre><code class="java">    @Test
    void match() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        MatchQueryBuilder queryBuilder = QueryBuilders.matchQuery(&quot;category&quot;, &quot;Men&#39;S Clothing&quot;);
        queryBuilder.operator(Operator.AND);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }</code></pre>
<h4 id="模糊查询"><a href="#模糊查询" class="headerlink" title="模糊查询"></a>模糊查询</h4><ul>
<li><p>wirdcard 模糊查询 分词匹配 *任意个 ?一个</p>
</li>
<li><p>regexp 模糊查询 正则匹配 </p>
</li>
<li><p>prefix 模糊查询 前缀匹配</p>
</li>
</ul>
<pre><code class="java">    @Test
    void wildcard() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        WildcardQueryBuilder queryBuilder = QueryBuilders.wildcardQuery(&quot;category&quot;, &quot;men&#39;s*&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }

    @Test
    void regexp() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        RegexpQueryBuilder queryBuilder = QueryBuilders.regexpQuery(&quot;category&quot;, &quot;men+(.)*&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }

    @Test
    void prefix() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        PrefixQueryBuilder queryBuilder = QueryBuilders.prefixQuery(&quot;category&quot;, &quot;m&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }
</code></pre>
<h4 id="范围查询-1"><a href="#范围查询-1" class="headerlink" title="范围查询"></a>范围查询</h4><pre><code class="java">    @Test
    void range() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        RangeQueryBuilder queryBuilder = QueryBuilders.rangeQuery(&quot;taxless_total_price&quot;);
        queryBuilder.gte(&quot;100&quot;);
        queryBuilder.lte(&quot;200&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }
</code></pre>
<h4 id="QueryString-1"><a href="#QueryString-1" class="headerlink" title="QueryString"></a>QueryString</h4><p>会分词，等值匹配，默认取并集，跟match差不多，但可指定多字段</p>
<pre><code class="java">    @Test
    void queryString() throws IOException {
        //查询请求
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询条件构造器
        SearchSourceBuilder searchRequestBuilder=new SearchSourceBuilder();
        //查询条件
        QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(&quot;+Sultan  -Pratt&quot;).field(&quot;customer_first_name&quot;).field(&quot;customer_full_name&quot;);
        //指定查询条件
        searchRequestBuilder.query(queryBuilder);
        //添加条件构造器
        searchRequest.source(searchRequestBuilder);
        //查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //获取结果集
        SearchHits searchHits=searchResponse.getHits();
        System.out.println(&quot;命中个数为: &quot;+searchHits.getTotalHits().value);
        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            String object=hit.getSourceAsString();
            System.out.println(object);

        }
    }</code></pre>
<h4 id="聚合查询-1"><a href="#聚合查询-1" class="headerlink" title="聚合查询"></a>聚合查询</h4><ul>
<li>指标聚合：相当于MySQL中的聚合函数，max，min，count，avg等</li>
<li>桶聚合：相当于MySQL的group by操作</li>
</ul>
<pre><code class="java">    @Test
    void agg() throws IOException {
        //请求对象
        SearchRequest searchRequest=new SearchRequest(&quot;kibana_sample_data_ecommerce&quot;);
        //查询构造器
        SearchSourceBuilder searchSourceBuilder=new SearchSourceBuilder();
        //查询添加
        MatchQueryBuilder queryBuilder = QueryBuilders.matchQuery(&quot;category&quot;, &quot;men&#39;s&quot;);
        //聚合查询
        TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(&quot;name&quot;).field(&quot;day_of_week_i&quot;).size(20);

        searchSourceBuilder.query(queryBuilder);
        searchSourceBuilder.aggregation(aggregationBuilder);
        searchRequest.source(searchSourceBuilder);
        //执行查询
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        SearchHits searchHits=searchResponse.getHits();

        System.out.println(&quot;命中数:&quot;+ searchHits.getTotalHits().value);

        SearchHit[] hits=searchHits.getHits();
        for (SearchHit hit : hits) {
            System.out.println(hit.getSourceAsString());
        }

        Map&lt;String, Aggregation&gt; stringAggregationMap = searchResponse.getAggregations().asMap();

        Terms name = (Terms) stringAggregationMap.get(&quot;name&quot;);
        for (Terms.Bucket bucket : name.getBuckets()) {
            System.out.println(bucket.getKey()+ &quot;:&quot; +bucket.getDocCount());

        }
    }</code></pre>

        </div>
        <!-- .entry-content -->
        
        <p></p>
          
        <div style="text-align:center; width: 100%" class="social-share share-mobile" data-disabled="diandian, tencent"></div>
        <footer class="post-footer">
          <div class="post-lincenses"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="nofollow"><i class="fa fa-creative-commons" aria-hidden="true"></i> 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></div>
          <div class="post-tags">
            <div class="tag-cloud">
              <div class="tag-cloud-title">
              </div>
              <div class="tag-cloud-tags">
              <a href="/tags/CDN/" style="font-size: 10px; color: #f38181">CDN</a> <a href="/tags/Chrome/" style="font-size: 10px; color: #f38181">Chrome</a> <a href="/tags/Collection/" style="font-size: 10px; color: #f38181">Collection</a> <a href="/tags/ElasticSearch/" style="font-size: 10px; color: #f38181">ElasticSearch</a> <a href="/tags/IO%E6%B5%81/" style="font-size: 10px; color: #f38181">IO流</a> <a href="/tags/JVM/" style="font-size: 10px; color: #f38181">JVM</a> <a href="/tags/Java/" style="font-size: 16.67px; color: #b4c1b8">Java</a> <a href="/tags/Linux/" style="font-size: 10px; color: #f38181">Linux</a> <a href="/tags/MySQL/" style="font-size: 10px; color: #f38181">MySQL</a> <a href="/tags/OIS/" style="font-size: 10px; color: #f38181">OIS</a> <a href="/tags/Redis/" style="font-size: 13.33px; color: #d4a19c">Redis</a> <a href="/tags/SQL/" style="font-size: 10px; color: #f38181">SQL</a> <a href="/tags/Springboot/" style="font-size: 10px; color: #f38181">Springboot</a> <a href="/tags/TCP-IP/" style="font-size: 10px; color: #f38181">TCP/IP</a> <a href="/tags/Tomcat/" style="font-size: 10px; color: #f38181">Tomcat</a> <a href="/tags/aop/" style="font-size: 10px; color: #f38181">aop</a> <a href="/tags/bili/" style="font-size: 10px; color: #f38181">bili</a> <a href="/tags/eclipse/" style="font-size: 10px; color: #f38181">eclipse</a> <a href="/tags/git/" style="font-size: 10px; color: #f38181">git</a> <a href="/tags/github/" style="font-size: 13.33px; color: #d4a19c">github</a> <a href="/tags/ioc/" style="font-size: 10px; color: #f38181">ioc</a> <a href="/tags/java/" style="font-size: 20px; color: #95e1d3">java</a> <a href="/tags/jsdelivr/" style="font-size: 10px; color: #f38181">jsdelivr</a> <a href="/tags/oracle/" style="font-size: 10px; color: #f38181">oracle</a> <a href="/tags/spring/" style="font-size: 13.33px; color: #d4a19c">spring</a> <a href="/tags/sring/" style="font-size: 10px; color: #f38181">sring</a> <a href="/tags/vscode/" style="font-size: 10px; color: #f38181">vscode</a> <a href="/tags/web/" style="font-size: 10px; color: #f38181">web</a> <a href="/tags/%E5%8F%8D%E5%B0%84/" style="font-size: 10px; color: #f38181">反射</a> <a href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 10px; color: #f38181">多线程</a> <a href="/tags/%E5%AE%9E%E4%B9%A0/" style="font-size: 10px; color: #f38181">实习</a> <a href="/tags/%E6%8E%92%E5%BA%8F/" style="font-size: 10px; color: #f38181">排序</a> <a href="/tags/%E6%B3%A8%E8%A7%A3/" style="font-size: 10px; color: #f38181">注解</a> <a href="/tags/%E6%B4%BE%E5%A4%A7%E6%98%9F/" style="font-size: 10px; color: #f38181">派大星</a> <a href="/tags/%E7%BD%91%E7%BB%9C/" style="font-size: 10px; color: #f38181">网络</a>
              </div>
            </div>
          </div>
          <div class="post-share">
            <div class="social-share sharehidden share-component"></div>
            <i class="iconfont show-share icon-forward"></i>
          </div>
        </footer><!-- .entry-footer -->
      </article>
      <!-- #post-## -->
      <div class="toc" style="background: none;"></div>
      <section class="post-squares nextprev">
        
        
          
            <div class="post-nepre full next">
          
            <a href="/posts/deb5175a.html" rel="next">
              <div class="background">
                
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-l322ql.jpg" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" >
              </div>
              <span class="label">
              Next Post</span>
              <div class="info">
                <h3>
                Linux学习</h3>
                <hr>
              </div>
            </a>
          </div>
        
      </section>
      
      <section class="author-profile">
        <div class="info" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
          <a href="" class="profile gravatar"><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg" itemprop="image" alt="Conor_hua" height="70" width="70"></a>
          <div class="meta">
            <span class="title">Author</span>
            <h3 itemprop="name">
            <a href="" itemprop="url" rel="author">Conor_hua</a>
            </h3>
          </div>
        </div>
        <hr>
        <p><i class="iconfont icon-write"></i></p>
      </section>
    </main><!-- #main -->
  </div><!-- #primary -->
</div>


    </div>    
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            // PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
    <!-- <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Conor_hua<br>
      powered_by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer> -->
<footer id="colophon" class="site-footer" role="contentinfo">
    <div class="site-info">
        <div class="footertext">
            <div class="img-preload">
                <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/wordpress-rotating-ball-o.svg">
                <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/disqus-preloader.svg">
            </div>
            
            <p>本站总访问量：<a id="allcount"></a></p>
            <p style="color: #666666;">it you can dream it you can do it</p>
            
                <p id="momk" style="font-family: 'Ubuntu', sans-serif;color: #b9b9b9;"></p>
            
        </div>
        <div class="footer-device">
            <p style="font-family: 'Ubuntu', sans-serif;">
 <span style=""> <a 
                         style="color: 	#FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Conor_hua</a> <i
             class="iconfont icon-sakura rotating" style="color: #ffc0cb;display:inline-block"></i> Theme <a
             href="https://github.com/xbclub/Hexo-theme-sakura" target="_blank"
             style="color: #FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Sakura</a><a
             
             style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">, Powered by</a><a
             href="https://github.com/hexojs/hexo" target="_blank"
             style="color: #FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);"> Hexo</a>
        </span>
            </p>
        </div>
    </div><!-- .site-info -->
    <!--壁纸切换-->
  <div class="skin-menu no-select" id="mainskin"  style="position: fixed">
    <div class="theme-controls row-container">
        <ul class="menu-list">
            <li id="white-bg"> <i class="fa fa-television" aria-hidden="true"></i></li>
            <li id="sakura-bg"> <i class="iconfont icon-sakura"></i></li>
            <li id="gribs-bg"> <i class="fa fa-slack" aria-hidden="true"></i></li>
            <li id="KAdots-bg"> <i class="iconfont icon-dots"></i></li>
            <li id="totem-bg"> <i class="fa fa-optin-monster" aria-hidden="true"></i></li>
            <li id="pixiv-bg"> <i class="iconfont icon-pixiv"></i></li>
            <li id="bing-bg"> <i class="iconfont icon-bing"></i></li>
            <li id="dark-bg"> <i class="fa fa-moon-o" aria-hidden="true"></i></li>
        </ul>
    </div>
    <div class="font-family-controls row-container">
        <button type="button" class="control-btn-serif selected" data-mode="serif" onclick="mashiro_global.font_control.change_font()">Serif</button>
        <button type="button" class="control-btn-sans-serif" data-mode="sans-serif" onclick="mashiro_global.font_control.change_font()">Sans Serif</button>
    </div>
</div>   
<canvas id="night-mode-cover"></canvas> 
  <div class="changeSkin-gear no-select">
    <div class="keys" id="setbtn"> <span id="open-skinMenu"> 切换壁纸 | SCHEME TOOL 
      &nbsp;<i class="iconfont icon-gear inline-block rotating"></i> </span></div>
</div><!--skin.end-->
</footer>


<!--<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.7/js/tocbot.min.js"></script>-->

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/InsightSearch.js"></script>
<script type="text/javascript"
        src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/jquery.fancybox.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/zoom.min.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@1.2/js/sakura-app.js"></script>
    
<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/Valine.min.js'></script>
<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/botui.js"></script>
<!-- 不蒜子 网页计数器 -->

      
       <script>
  fetch('https://counts.42cloud.cn/api/counts.html')
        .then(response => response.json())
        .then(data => {
              if (document.getElementById("readcount")) {
                document.getElementById("readcount").innerHTML=data.Count;
            }
            if (document.getElementById("allcount")){
                document.getElementById("allcount").innerHTML=data.Allcount;
            }
        })
        .catch(err => console.error(err))
</script>
      
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script> -->
<script type="text/javascript">
    /* <![CDATA[ */
    if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        var Poi = {
            "pjax": "1",
            "movies": {"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2", "name": "Unbroken.mp4", "live": "close"},
            "windowheight": "fixed",
            "codelamp": "close",
            "ajaxurl": "",
            "order": "asc",
            "formpostion": "bottom"
        };
    } else {
        var Poi = {
            "pjax": "1",
            "movies": {"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2", "name": "Unbroken.mp4", "live": "open"},
            "windowheight": "auto",
            "codelamp": "close",
            "ajaxurl": "",
            "order": "asc",
            "formpostion": "bottom"
        };
    }
    /* ]]> */

</script>
<script>
    $(document).ready(function () {
        if ($(".toc").length > 0 && document.body.clientWidth > 1200) {
            if ($(".pattern-center").length > 0) { //有图的情况
                tocbot.init({
                    // Where to render the table of contents.
                    tocSelector: '.toc', // 放置目录的容器
                    // Where to grab the headings to build the table of contents.
                    contentSelector: '.entry-content', // 正文内容所在
                    // Which headings to grab inside of the contentSelector element.
                    scrollSmooth: true,
                    headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
                    headingsOffset: -400,
                    scrollSmoothOffset: -85
                });
            } else {
                tocbot.init({
                    // Where to render the table of contents.
                    tocSelector: '.toc', // 放置目录的容器
                    // Where to grab the headings to build the table of contents.
                    contentSelector: '.entry-content', // 正文内容所在
                    // Which headings to grab inside of the contentSelector element.
                    scrollSmooth: true,
                    headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
                    headingsOffset: -85,
                    scrollSmoothOffset: -85
                });
            }
            var offsetTop = $('.toc').offset().top - 95;
            window.onscroll = function () {
                var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
                if (scrollTop >= offsetTop) {
                    $('.toc').addClass('toc-fixed');
                } else {
                    $('.toc').removeClass('toc-fixed');
                }
            }
        }
    });

</script>
<span style="color: #FF69B4 ;padding-left: 20px;">
    <i class="fa fa-clock-o" aria-hidden="true"></i>
    <span id="time" align="center">载入时间中...</span>

    <script type="text/javascript">
        function NewDate(str) {
            str = str.split('-');
            var date = new Date();
            date.setUTCFullYear(str[0], str[1] - 1, str[2]);
            date.setUTCHours(0, 0, 0, 0);
            return date;
        }

        function momxc() {
            var birthDay = NewDate("2020-7-16");
            var today = new Date();
            var timeold = today.getTime() - birthDay.getTime();
            var sectimeold = timeold / 1000
            var secondsold = Math.floor(sectimeold);
            var msPerDay = 24 * 60 * 60 * 1000;
            var e_daysold = timeold / msPerDay;
            var daysold = Math.floor(e_daysold);
            var e_hrsold = (daysold - e_daysold) * -24;
            var hrsold = Math.floor(e_hrsold);
            var e_minsold = (hrsold - e_hrsold) * -60;
            var minsold = Math.floor((hrsold - e_hrsold) * -60);
            var seconds = Math.floor((minsold - e_minsold) * -60).toString();
            document.getElementById("momk").innerHTML = "本小破站已勉强维持生活" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
            setTimeout(momxc, 1000);
        }
        
        momxc();
    </script>


</span>


    <div class="openNav no-select" style="height: 50px;">
      <div class="iconflat no-select" style="width: 50px; height: 50px;">
        <div class="icon"></div>
      </div>
      <div class="site-branding search-form-submit">
        <i class="iconfont js-toggle-search iconsearch icon-search"></i>
      </div>
    </div>
  </section>
  <div id="mo-nav" class="">
  <div class="m-avatar">
    <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
  </div>
  <p style="text-align: center; color: #333; font-weight: 900; font-family: 'Ubuntu', sans-serif; letter-spacing: 1.5px">Conor_hua</p>
  <p style="text-align: center; word-spacing: 20px;">
    
  </p>
  <ul id="menu-new-1" class="menu">
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
            首页
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/archives">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
            归档
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/categories/%E6%8A%80%E6%9C%AF/">
                  <i class="fa fa-code" aria-hidden="true"></i>
                  技术
                </a>
              </li>
            
              <li>
                <a href="/categories/%E5%B9%B2%E8%B4%A7/">
                  <i class="fa fa-plug" aria-hidden="true"></i>
                  干货
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
            清单
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/bangumis/">
                  <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                  番剧
                </a>
              </li>
            
              <li>
                <a href="/categories/%E6%94%B6%E8%97%8F/">
                  <i class="fa fa-star" aria-hidden="true"></i>
                  收藏
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/tags/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-tags" aria-hidden="true"></i>
            标签
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
            关于
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/about/">
                  <i class="fa fa-meetup" aria-hidden="true"></i>
                  我？
                </a>
              </li>
            
              <li>
                <a href="/theme-sakura/">
                  <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                  主题
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/links/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
            友人帐
          </span>
        </a>
        
      </li>
    
  </ul>
  <p style="text-align: center; font-size: 13px; color: #b9b9b9;">&copy 2019 hexo-sakura</p>
</div>
<button onclick="topFunction()" class="mobile-cd-top" id="moblieGoTop" title="Go to top" style="display: none;"><i class="fa fa-chevron-up" aria-hidden="true"></i></button>
  
</body>
<script src="https://cdn.jsdelivr.net/gh/conorhua/asset/js/noSomeKey.js"></script>
</html>